//
//  KDOneViewController.m
//  YuQingXiaoFang
//
//  Created by wangdongdong on 18/6/6.
//  Copyright © 2018年 KDTech. All rights reserved.
//

#import "KDHomeViewController.h"
#import "KDTwoViewController.h"
#import "KDThreeViewController.h"
#import "KDCollectController.h"
#import "KDChildCollectController.h"
#import "KDCollectRequestTool.h"
#import "KDFavorTypeListResult.h"
#import "KDFavorType.h"
#import "KDTabBarController.h"
#import "KDLoginTool.h"
#import "AFNetworking.h"
#import "KDAccount.h"
#import "KDMessagePushController.h"
#import "KDNewsController.h"
#import "KDEarlyWaringController.h"
#import "KDOverwideNavigationController.h"
#import "KDNetExpController.h"
@interface KDHomeViewController ()<UITextFieldDelegate ,UINavigationControllerDelegate>
@property (nonatomic,retain) NSDateFormatter *fmt;
@end

@implementation KDHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self initTopWithData];
    [self initBannerImage];
    
    KDNewsController *two1=[[KDNewsController alloc] init];
    two1.title=@"two1";
    two1.newsType=NEW_TYPE_INTERNEWS;
    [self addChildViewController:two1];

	
    
    KDNewsController *three1=[[KDNewsController alloc] init];
    three1.title=@"three1";
    three1.newsType=NEW_TYPE_HEADLINES;
    [self addChildViewController:three1];
    
    KDNetExpController *two2=[[KDNetExpController alloc] init];
    two2.title=@"two2";
    [self addChildViewController:two2];
    
    KDEarlyWaringController *three2=[[KDEarlyWaringController alloc] init];
    three2.title=@"three2";
    [self addChildViewController:three2];
    
    KDTwoViewController *two3=[[KDTwoViewController alloc] init];
    two3.title=@"two3";
    [self addChildViewController:two3];

    KDNewsController *three3=[[KDNewsController alloc] init];
    three3.title=@"three3";
    three3.newsType=NEW_TYPE_ABROAD;
    [self addChildViewController:three3];
    
    KDOverwideNavigationController *two4=[[KDOverwideNavigationController alloc] init];
    two4.title=@"two4";
    [self addChildViewController:two4];

    
    
    
    self.needUnderLine = NO;
    
    
     
    [super setupAllTitle];
}

//初始化首页顶部
-(void) initTopWithData{
    
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithTitle:@"退出" style:UIBarButtonItemStyleDone target:self action: @selector(loginoutSS:) ];
    
    KDAccount *account = [KDAccountTool account];
    NSString *time =[self.fmt stringFromDate:[[NSDate alloc] init]];
    NSString *userNameAndTime=[NSString stringWithFormat:@"%@ %@",account.userName,time];
    self.navigationItem.title=userNameAndTime;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void) initBannerImage{
    
    KDLog(@"%f",screenH);

    //初始化
    UIImageView  *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenW,homeTopBannerH)];
    
    //需要设置图片 UIImage
    imageView.image = [UIImage imageNamed:@"banner"];
    
    [self.view addSubview:imageView];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
-(void) loginOutDialog{
    
}
/**
 *  退出登录按钮被点击了
 */
-(IBAction)loginoutSS:(UIButton * )sender{
    KDBaseParam *param = [[KDBaseParam alloc]init];
    //    param.method = @"logout";
    [KDLoginTool logoutWithParam:param success:^(KDBaseResult *responseObejct) {
        //        if ([responseObejct.msg isEqualToString:@"操作成功"]) {//退出成功
        KDLog(@"%@",responseObejct.msg);
        [[NSNotificationCenter defaultCenter] postNotificationName:@"LogoutNoty" object:nil userInfo:nil];
        
        KDNewfeatureController *new  = [[KDNewfeatureController alloc]init];
        __block KDTabBarController*ctr = (KDTabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
        [UIApplication sharedApplication].keyWindow.rootViewController = new;
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [ctr removeObserver];
            [ctr removeFromParentViewController];
            ctr = nil;
        });
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误！" maskType:SVProgressHUDMaskTypeGradient];
    }];

}

- (NSDateFormatter *)fmt
{
    if (!_fmt) {
        _fmt = [[NSDateFormatter alloc]init];
        _fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];;
        _fmt.dateFormat = @"YYYY-MM-dd HH:mm:ss";
    }
    return _fmt;
}

@end
